<div class="portlet col-xs-2 padding0" style="overflow: auto;width:15%;margin-right:10px;">
	<div class="portlet-title">
		<span class="glyphicon glyphicon-tree-deciduous" aria-hidden="true">组织结构</span>
	</div>
	<ul id='orgtree'></ul>
</div>
<div class="portlet col-xs-10 padding0">
	<div class="portlet-title">
		<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span> <span>终端列表</span>
		<form class="form-inline pull-right" onsubmit="return false">
			<label for="termKey">关键字</label> 
			<input type="text" id="termKey" class="form-control" placeholder="要查询的关键字" />
			<label for="eqptMpStatus">状态</label>
			<select class="form-control" id="termStatus">
			<option value="-1">所有</option>
			<option value="1">未绑定</option>
			<option value="0">已绑定</option>
			<option value="2">待绑定</option>
			</select>
		<button type="button" class="btn btn-xs btn-info" onclick="showTermList()">查询</button>
		<button type="button" prid="allotTerm" class="btn btn-info btn-xs" style="margin-right:10px" onclick="allotTerms()">批量下发</button>
	</form>
</div>
<div id="termDataGrid" class='portlet-box'></div></div>
<script type="text/javascript">
callSvr("OrgManage/getOrgListByPid",{"type":"-1"},function(result){
	$('#orgtree').height($("#main").height() - 135);
	$('#orgtree').TreeView(result,function(activeLi){
		$("#orgtree").data("activeorgid",activeLi.data('value'));
		showTermList();
	});
	showTermList();
	});
	function showTermList() {
		var operations = [ {
			"name" : "下发终端",
			"callback" : "allotTerm",
			"attr" : function(row) {
				if (row["状态"] == "已绑定") {
					return "disabled";
				} else {
					return "";
				}
			},
			"width":0.09
		} ];
		var conditions = [{"column":"termkey","value":$("#termKey").val().trim(),"rule":""},
		                  {"column":"status","value":$("#termStatus").val().trim(),"rule":""},
		                  {"column":"treeorgid","value":$("#orgtree").data("activeorgid"),"rule":""}];
		$("#termDataGrid").fdatagrid({
			operation : operations,
			reportId : 'getTerm',
			condition : conditions});
	}
	var termDialog = {
		windowId : "Random",
		popWidth : 400,
		popHeight : 150,
		position : "center",
		src : "../eqpt/term_dialog.html",
		title : ""
	};
	function allotTerm(i) {
		em.termCode="'"+$('#termDataGrid').find("tr:eq(" + (i + 1) + ")").find(
		"td:eq(1)").html()+"'";
		termDialog.title = "下发终端";
		Dialog = popWindowShow(termDialog);
	}
	function allotTerms() {
		em.termCode= "'";
		var _termCodeObj = $("[name=id]:checked");
		if(_termCodeObj.length==0){
			alert("请选择要下发的终端");
		}else{
			for (var i = 0; i < _termCodeObj.length; i++) {
				em.termCode += _termCodeObj.eq(i).val();
				if (i != _termCodeObj.length - 1) {
					em.termCode += "','";
				}else{
					em.termCode += "'";
				}
			}
			termDialog.title = "下发终端";
			Dialog = popWindowShow(termDialog);
		}
	}
	function selectAll(obj) {
		var checkboxs = $("[name=id]:not(:disabled)");
		for (var i = 0; i < checkboxs.length; i++) {
			var e = checkboxs[i];
			e.checked = obj.checked;
		}
	}

	function checkSelect() {
		var checkboxs = $("[name=id]:not(:disabled)");
		var checkboxsSelect = $("[name=id]:not(:disabled):not(:checked)");
		var finds = checkboxsSelect.length;
		if (finds == 0) {
			$("#ids").prop("checked", true);
		} else {
			$("#ids").prop("checked", false);
		}
	}
</script>
